package com.changgou.config;

import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * mq配置信息
 * 
 * @author gaofeng
 * @date 2025/4/28 19:46
 */
@Configuration
public class RabbitmqConfig {
    /**
     * 交换机
     */
    public static final String EXCHANGE_NAME = "page_exchange";

    /**
     * 队列
     */
    public static final String QUEUE_NAME = "page_queue";

    /**
     * 路由key
     */
    public static final String ROUTING_KEY = "page_key";

    @Bean
    public SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory() {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
        factory.setConcurrentConsumers(3);
        factory.setMaxConcurrentConsumers(10);
        factory.setPrefetchCount(100);
        factory.setTxSize(3);
        return factory;
    }

    /**
     * 自定义ConnectionFactory
     * 
     * @return org.springframework.amqp.rabbit.connection.ConnectionFactory
     **/
    public static ConnectionFactory connectionFactory() {
        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
        cachingConnectionFactory.setAddresses("192.168.3.77");
        cachingConnectionFactory.setUsername("guest");
        cachingConnectionFactory.setPassword("guest");
        cachingConnectionFactory.setPort(5672);
        return cachingConnectionFactory;
    }
}
